package com.d.business.controller;

import java.util.List;
import java.util.Map;

import com.d.common.utils.RT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.d.business.domain.DingProcessConfItemDO;
import com.d.business.service.DingProcessConfItemService;
import com.d.common.utils.PageUtils;
import com.d.common.utils.Query;

/**
 * 此表用作配置钉钉和业务代码的映射
用作替代DingFromConstants的内容
 *
 * @author wang
 * @email wangfst@foxmail.com
 * @date 2025-07-31 10:00:26
 */

@Controller
@RequestMapping("/system/dingProcessConfItem")
public class DingProcessConfItemController {
	@Autowired
	private DingProcessConfItemService dingProcessConfItemService;

	@GetMapping()
	String DingProcessConfItem(){
	    return "system/dingProcessConfItem/dingProcessConfItem";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DingProcessConfItemDO> dingProcessConfItemList = dingProcessConfItemService.list(query);
		int total = dingProcessConfItemService.count(query);
		PageUtils pageUtils = new PageUtils(dingProcessConfItemList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "system/dingProcessConfItem/add";
	}

	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Integer id,Model model){
		DingProcessConfItemDO dingProcessConfItem = dingProcessConfItemService.get(id);
		model.addAttribute("dingProcessConfItem", dingProcessConfItem);
	    return "system/dingProcessConfItem/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public RT save( DingProcessConfItemDO dingProcessConfItem){
		if(dingProcessConfItemService.save(dingProcessConfItem)>0){
			return RT.ok();
		}
		return RT.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
 	public RT update(DingProcessConfItemDO dingProcessConfItem){
		dingProcessConfItemService.update(dingProcessConfItem);
		return RT.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ResponseBody
	public RT remove( Integer id){
		if(dingProcessConfItemService.remove(id)>0){
			return RT.ok();
		}
		return RT.error();
	}
}
